
#ifndef __KHAN_TELNET_OPT_HPP__
#define __KHAN_TELNET_OPT_HPP__

#include <arpa/telnet.h>    /* for telnet opt */

#include "khan.hpp"

class telnet_opt 
:private boost::noncopyable       
{
public:
    typedef enum 
    { 
        SGA_OPT, NAWS_OPT, ECHO_OPT, LINE_OPT 
    }OPT_TYPE;
    

    telnet_opt():
        _width(0),
        _height(0)
    { init(); }
    ~telnet_opt() {};

    const std::string&  get_option_str(const OPT_TYPE type);
    bool    is_iac() { return (_iac == 1); };
    void    clear_iac() { _iac = 0; };
    int     check_opt(unsigned char c);
    int     handle_opt(unsigned char c);
    void    dump(unsigned char* buf, int len);
     
private:
    typedef std::map<OPT_TYPE, std::string> opt_map_type;

    enum { 
        OPT_SIZE = 3,
        TELNET_NAWS_SB_LEN = 5  
    };

    void    init();
    
    unsigned char   _iac;          
    unsigned char   _iac_sb_in_progress;
    unsigned char   _sb_buf[TELNET_NAWS_SB_LEN];
    size_t          _sb_len;
    int             _width;
    int             _height;
    opt_map_type    _opt_maps;
};


#endif /* __KHAN_TELNET_OPT_HPP__ */
